package com.lv.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lv.mapper.TbSellerMapper;
import com.lv.model.TbSeller;
import com.lv.model.TbSellerExample;
import com.lv.service.SellerService;
import com.lv.vo.SellerVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SellerServiceImpl implements SellerService {

    @Resource
    private TbSellerMapper sm;

    //查询未审核的

    @Override
    public List<SellerVo> selectByStatus() {
        TbSellerExample example = new TbSellerExample();
        TbSellerExample.Criteria criteria = example.createCriteria();
        criteria.andStatusEqualTo("0");
        List<TbSeller> tbSellers = sm.selectByExample(example);
        List<SellerVo> vos = JSONObject.parseArray(JSON.toJSONString(tbSellers), SellerVo.class);
        return vos;
    }

    @Override
    public void update(List<String> ids) {
        TbSellerExample example = new TbSellerExample();
        TbSellerExample.Criteria criteria = example.createCriteria();
        criteria.andSellerIdIn(ids);
        List<TbSeller> tbSellers = sm.selectByExample(example);
        for (TbSeller seller : tbSellers){
            seller.setStatus("1");
            sm.updateByPrimaryKeySelective(seller);
        }
    }
}
